import type { IQuery, IResponse, TableResponse } from '@/api/config/types';
import axios from 'axios';

export type LibraryType = '0' | '1' | '2' | '3' | '4' | '5';

export interface Library {
  resId: string;
  name: string;
  type: LibraryType;
  lang: string;
  word: string;
  uri: string;
  reason?: string;
  /* 0:私有，1：共享 */
  share: '0' | '1';
  md5: string;
  format: string;
  bytes: number;
  oss: '0' | '1';
  /* 0：正常，1：审核中，2：被驳回 */
  status: '0' | '1' | '2';
  deptId: string;
  sizeId: string;
  createBy: string;
  createTime: string;
  updateBy?: any;
  updateTime?: any;
  cover: string;
}
export interface RejectData {
  resId: string;
  reason: string;
}

const prefix = '/library/library';

// 获取图书馆列表
export const libraryList = (query: IQuery) => {
  return axios.get<TableResponse<Library>>(`${prefix}/list`, { params: query });
};

// 创建图书馆
export const createLibrary = (data: Library) => {
  return axios.post<IResponse>(`${prefix}`, data);
};

// 更新图书馆
export const updateLibrary = (data: Library) => {
  return axios.put<IResponse>(`${prefix}`, data);
};

// 获取单个图书馆
export const getLibrary = (id: string | number) => {
  return axios.get<IResponse<Library>>(`${prefix}/${id}`);
};

// 删除图书馆
export const deleteLibrary = (ids: (number | string)[]) => {
  return axios.delete<IResponse>(`${prefix}/${ids.join(',')}`);
};

// 图书馆通过
export const libraryThrough = (ids: (number | string)[]) => {
  return axios.get(`${prefix}/through/${ids.join(',')}`);
};

// 拒绝图书馆数据
export const reject = (data: RejectData) => {
  return axios.post<IResponse>(`${prefix}/reject`, data);
};

// 同步素材管理
export const librarySync = (from: string, to: string) => {
  return axios.get(`${prefix}/sync`, { params: { from, to } });
};
